package com.wzs.rpc.protocol;

import lombok.Getter;

@Getter
public enum ProtocolMessageSerializerEnum {
    JDK(0, "com.wzs.rpc.serializer.JDKSerializer"),
    JSON(1,"com.wzs.rpc.serializer.JsonSerializer"),
    KRYO(2,"com.wzs.rpc.serializer.KryoSerializer"),
    HESSIAN(3,"com.wzs.rpc.serializer.HessianSerializer");
    private int code;
    private String name;
    ProtocolMessageSerializerEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据code获取枚举
     */
    public static ProtocolMessageSerializerEnum getEnumByValue(int code) {
        for (ProtocolMessageSerializerEnum protocolMessageSerializerEnum : ProtocolMessageSerializerEnum.values()) {
            if (protocolMessageSerializerEnum.getCode()==code) {
                return protocolMessageSerializerEnum;
            }
        }
        return null;
    }

    /**
     * 根据name获取枚举
     */
    public static ProtocolMessageSerializerEnum getEnumByName(String name) {
        for (ProtocolMessageSerializerEnum protocolMessageSerializerEnum : ProtocolMessageSerializerEnum.values()) {
            if (protocolMessageSerializerEnum.getName().equals(name)) {
                return protocolMessageSerializerEnum;
            }
        }
        return null;
    }
}
